<template>
	<!--pages/login/index.wxml-->
	<view class="apply_box">
		<mineNavbar :styleData="styleData"></mineNavbar>
		<scroll-view class="a_contain" v-if="applyList.length" scroll-y @scrolltolower="scrollBottomFn">
			<view class="c_list">
				<view class="l_item" v-for="item in applyList" :key="item">
					<view class="i_one">
						<view :style="{ background: getTypeColorFun(item.positionType) }">{{
							item.positionTypeLabel || '' }}</view>
						<view>{{ item.positionName || '' }}</view>
					</view>
					<view class="i_two">
						<text>￥</text>
						<text v-if="item.positionType !== '1'">{{ item.startSalary }}~{{ item.endSalary }}</text>
						<text v-else>{{ item.startSalary }}</text>
						<text>/{{ item.salaryPeriodLabel || '' }}</text>
					</view>
					<view class="i_three">
						<view>
							<image src="../../../../static//images/recruit/icon1.png" />
							<text>{{ item.fullName || '' }}</text>
						</view>
					</view>
					<view class="i_four">
						<view @click="handleCancelCollect(item.positionId)">取消收藏</view>
						<view @click="handleDelivery(item.positionId)">查看岗位</view>
					</view>
					<!-- <view class="i_four active" v-else>
						<text class="text">岗位已暂停</text>
						<view @click="handleCancelCollect(item.positionId)">取消收藏</view>
					</view> -->
				</view>
				<view class="downLoad">-- 加载完成，共{{ applyList.length }}条数据 --</view>
			</view>
		</scroll-view>
		<noneState v-else></noneState>
	</view>
</template>
  
<script>

import { getCollectList, cancelCollect } from "@/api/pages/mine.js"
import noneState from '@/pages/recruit/components/noneState.vue'

export default {
	components: { noneState },
	data() {
		return {
			styleData: {
				show: true,
				tabbarText: '职位收藏'
			},
			pageSize: 10,
			pageNum: 1,
			pageTotal: 1,
			activeType: 1,
			applyList: []
		};
	},
	computed: {},
	watch: {},
	async onLoad(options) {
		this.getCollectListFun()
	},
	async onShow() {
		this.pageNum = 1
	},
	onReady() { },
	methods: {
		// 切换类型
		handleActive(e) {
			console.log(e);
			this.activeType = e
		},
		// 获取类型颜色
		getTypeColorFun(positionType) {
			console.log(positionType);
			if (positionType === '1') {
				return "#34A1FF"
			}
			if (positionType === '2') {
				return "#71C465"
			}
			if (positionType === '3') {
				return "#F32763"
			}
		},
		//获取我的收藏列表
		getCollectListFun() {
			getCollectList({ pageNum: this.pageNum, pageSize: this.pageSize }).then((res) => {
				if (res.code == 200) {
					this.pageTotal = Math.ceil(res.total / this.pageSize)
					if (this.pageNum === 1) {
						this.applyList = res.rows
					} else {
						res.rows.forEach((suc) => {
							this.applyList.push(suc)
						})
					}
				}
			})
		},
		// 取消收藏
		handleCancelCollect(id) {
			console.log(id);
			cancelCollect({
				positionId: id,
				state: false
			}).then((res) => {
				if (res.code === 200) {
					this.applyList.forEach((e, index) => {
						console.log(this.applyList);
						if (e.positionId === id) {
							this.applyList.splice(index, 1)
						}
					})
				}
			})
		},
		//立即投递
		handleDelivery(id) {
			uni.navigateTo({
				url: '/pages/recruit/post/postDetail/index?positionId=' + id
			})
		},
		// 监听滑动到底部
		scrollBottomFn() {
			this.pageNum += 1
			if (this.pageNum <= this.pageTotal) {
				this.getCollectListFun()
			} else {
				uni.showToast({
					title: '没有更多了',
				});
			}
		},
	},
};
</script>
<style lang="scss" scoped>
/* pages/login/index.wxss */
.apply_box {
	width: 100%;
	height: 100vh;

	.a_contain {
		width: 100%;
		height: calc(100vh - 140rpx);

		.c_list {
			width: 100%;
			display: flex;
			flex-direction: column;
			align-items: center;

			.l_item {
				width: 702rpx;
				height: 324rpx;
				padding: 0 24rpx;
				box-sizing: border-box;
				font-size: 24rpx;
				background: #fff;
				margin: 10rpx 0;
				border-radius: 16rpx;

				>view {
					display: flex;
					align-items: center;
				}

				.i_one {
					margin-top: 30rpx;
					margin-bottom: 40rpx;

					>view:first-child {
						padding: 4rpx 12rpx;
						color: #fff;
						border-radius: 6rpx;
						margin-right: 10rpx;
					}

					>view:last-child {
						font-size: 32rpx;
						color: #000000e0;
					}
				}

				.i_two {
					>text:nth-child(2) {
						font-size: 32rpx;
						color: #FF9E24;
						margin-left: 5rpx;
					}
				}

				.i_three {
					justify-content: space-between;
					margin: 20rpx 0;

					image {
						width: 28rpx;
						height: 28rpx;
						margin-right: 10rpx;
					}

					.right {
						color: #00000073;
					}
				}

				.i_four {
					width: 100%;
					justify-content: flex-end;
					border-top: 1px #f0f0f0 solid;
					height: 110rpx;

					>view {
						width: 170rpx;
						height: 64rpx;
						border: 1px solid #00000033;
						border-radius: 44rpx;
						color: #000000e0;
						line-height: 64rpx;
						text-align: center;
						margin-left: 20rpx;
					}

					.text {
						font-size: 28rpx;
						color: #00000073;
					}
				}

				.active {
					justify-content: space-between;
				}
			}
		}

		.downLoad {
			font-size: 24rpx;
			color: #00000033;
			width: 100%;
			height: 80rpx;
			line-height: 80rpx;
			text-align: center;
			margin-bottom: 20rpx;
		}
	}
}
</style>
  